import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'

export default class CreateTwin {
    constructor(options) {
        // this.container = document.body;
        this.options=Object.assign({},options);
        this.container=this.options.container||document.body;
        this.gltfLoader = new GLTFLoader();
        // 场景
        this.scene = new THREE.Scene();
        // 相机
        const width = window.innerWidth;
        const height = window.innerHeight;
        this.camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 3000);
        this.camera.position.set(5, 1.6, 5);
        // 渲染器
        this.renderer = new THREE.WebGLRenderer({
            antialias: true,
            logarithmicDepthBuffer: true,
        });
        this.renderer.setPixelRatio(window.devicePixelRatio);
        this.renderer.setSize(width, height);
        this.container.appendChild(this.renderer.domElement);

        //axesHelper
        const axesHelper = new THREE.AxesHelper(2);
        this.scene.add(axesHelper);
       
        // 相机控件
        this.controls = new OrbitControls(this.camera, this.renderer.domElement);
        this.controls.target.set(0, 0, 0);
        this.controls.update();
        // 画布尺寸随着窗口变化
        window.addEventListener('resize',()=>{
            this.renderer.setSize(window.innerWidth, window.innerHeight);
            this.camera.aspect = window.innerWidth / window.innerHeight;
            this.camera.updateProjectionMatrix();
        });


         // 渲染循环
         this.renderer.setAnimationLoop(() => {
            this.renderer.render(this.scene, this.camera)
        })

    }
}
